How to make enemy shooting

54

How to make enemy shooting -

// Some Attribute
public float fireRate = 0.5f;
private float nextFire = 0.0f;

// In Update
if(Time.time > nextFire) {
    if(!Bullet)
        return;
    nextFire = Time.time + fireRate;
    GameObject clone = Instantiate(Bullet, ShootPoint.position,ShootPoint.rotation);
    Rigidbody rb = clone.GetComponent<Rigidbody>();
    rb.AddRelativeForce(Vector3.forward * bulletSpeed, ForceMode.Impulse);
}

Comments

Submit
0 Comments